<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>상품 디테일!</title>
<script type="text/javascript">
	<%
	HttpSession session2 = request.getSession();
	String userId = (String)session.getAttribute("userid");
	%>
	var userId = <%=userId%>;
	function check(){
		if(userId == null){
			alert("로그인 후 사용 가능합니다!.");
			location.href='../main/memberlogin.do';
		}else{
			document.order.submit();
			return false;
		}
	}

	function check2(){
		var code = ${board.p_code};
		if(userId == null){
			alert("로그인 후 사용 가능합니다!.");
			location.href='../main/memberlogin.do';
		}else{
			location.href='detailBest.do?p_code='+code+'&userid='+userId;
	
			
			}
			return false;
		}
</script>
</head>
<body>

<br><br><br>

<form:form action="order.do" method="get" commandName="board" name="order">
<table border="1" id=pro>
	<tr>
		<td>
			<img src="../adminproductupload/${board.p_previewimage1}" width="500" height="500"><br>
			 상품 수량 : <font color=red>${board.p_amount}</font> / 남은 시간 : <font color=red>${board.p_time}</font> / 구매자  : <font color=red>${board.p_buynum}</font> 명 <br>
			 
			<c:if test="${!empty board.p_previewimage2}">
			<img src="../adminproductupload/${board.p_previewimage2}" width="70" height="70">
			</c:if>
			
			<c:if test="${!empty board.p_previewimage3}">  
			<img src="../adminproductupload/${board.p_previewimage3}" width="70" height="70">
			</c:if>
		</td>
		<td>		
			<%	
				HttpSession session3 = request.getSession();
				String userId2 = (String)session.getAttribute("userid");
			 %>
													<input type="hidden" value="<%=userId2 %>" name="userid">
				<font size=4>상품 이름  : ${board.p_name}<input type="hidden" name="or_name" value="${board.p_name}"></font><br>
				<font size=4>상품 코드 : ${board.p_code}<input type="hidden" name="p_code" value="${board.p_code}"></font><br>
				<font size=4>상품 가격 : ${board.p_price}<input type="hidden" name="or_total" value="${board.p_price}"></font><br>
				<font size=4>상품 포인트 : ${board.p_point}</font><br>
				<font size=4>상품 추가 포인트 : ${board.p_addpoint}</font><br>
				<font size=4>주문 수량 : <select name="or_qtity">
												<option value="1">1</option>
												<option value="2">2</option>
												<option value="3">3</option>
												<option value="4">4</option>
												<option value="5">5</option>
										</select>
										</font><br>
					
				<font size=4>옵션 :</font><form:select name="p_option" id="p_option" path="p_option" items="${p_option}"/><br>
																		
				<font size=4>추천 : ${board.p_best}</font>
			
				<input type="button" value="추천하기" onclick="check2()" >	
				<br>
				
				<c:if test="${param.sc == '1'}">
				추천 횟수가 초과 되었습니다!
				</c:if>
			
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				
				<br>
				<br>
				<input type="submit" value="구매" onclick="check()">
				<input type="button" value="마일리지 충전" onclick="location.href='milege.do'">	 
		</td>
	</tr>
</table>
</form:form>
<br><br><br><br>
<table width="850" id="1">
	<tr>
		<td align="center" bgcolor="yellow"><a href=#1>제품 정보</a></td>
		<td align="center" bgcolor="aqua"><a href=#2>제품 리뷰</a></td>
		<td align="center" bgcolor="aqua"><a href=#3>제품 QnA</a></td>
	</tr>
	<tr>	 
		<td colspan="3" align="center">
		
		${board.p_content}<br>
		
		<img src="../adminproductupload/${board.p_productimage1}" width="500" height="500"><br>
		
		<c:if test="${!empty board.p_productimage2}">
		<img src="../adminproductupload/${board.p_productimage2}" width="500" height="500"><br>
		</c:if>
		
		<c:if test="${!empty board.p_productimage3}">
		<img src="../adminproductupload/${board.p_productimage3}" width="500" height="500"><br>
		</c:if>
		
		</td> 
	</tr>
</table>

<br>

<table width="800" id="2">
	<tr>
		<td align="center" bgcolor="aqua"><a href=#1>제품 정보</a></td>
		<td align="center" bgcolor="yellow"><a href=#2>제품 리뷰</a></td>
		<td align="center" bgcolor="aqua"><a href=#3>제품 QnA</a></td>
	</tr>
</table>
<form action="writeReivew.do" method="get" name="reiview">
<input type="hidden" value="${board.p_code}" name="p_code">
<table width="800" border="0" cellspacing="0" cellpadding="2">
	<tr bgcolor="#F3F3F3">
		<th width="50">번호</th>
		<th>제목</th>
		<th width="70">글쓴이</th>
		<th width="100">날짜</th>
		<th width="50">조회수</th>
	</tr>
	<tr bgcolor="#777777">
		<td height="1" colspan="5"></td>
	</tr>
	
	<!-- 리스트 불러오는 부분 -->
	
	<c:forEach var="rev" items="${list}">
		<tr>
			<td align="center">
				${number}
				<c:set var="number" value="${number-1}"/>
			</td>
			<td>
				<a href="reviewDetail.do?pr_num=${rev.pr_num}">${rev.pr_title}</a>
			</td>
			<td>${rev.userid}</td>
			<td><fmt:formatDate value="${rev.pr_writeday}" pattern="yyyy년 MM월 dd일"/></td>
			<td>${rev.pr_readcnt}</td>
		</tr>	
	</c:forEach>
	<!-- 리스트가 없으면 출력 -->
	<c:if test="${count == 0}">
		<tr align="center">
			<td colspan="5">등록된 게시물이 없습니다.</td>
		</tr>
			<tr bgcolor="#777777">
			<td height="1" colspan="5"></td>
		</tr>
	</c:if>
	<tr>
		<td align="center" colspan="5">${pagingHtml}</td>
	</tr>
	<tr>
		<td align="right" colspan="5">
			<input type="submit" value="글쓰기"> 		       
		</td>
	</tr>
</table>
</form>

<br>


<!-- 제품 qna -->

<table width="800" id="3">
	<tr>
		<td align="center" bgcolor="aqua"><a href=#1>제품 정보</a></td>
		<td align="center" bgcolor="aqua"><a href=#2>제품 리뷰</a></td>
		<td align="center" bgcolor="yellow"><a href=#3>제품 QnA</a></td>
	</tr>
</table>

<br><br><br><br><br>

</body>
</html>    